
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllUnits", query = "select myUnit from Unit myUnit"),
		@NamedQuery(name = "findUnitById", query = "select myUnit from Unit myUnit where myUnit.id = ?1"),
		@NamedQuery(name = "findUnitByMemo", query = "select myUnit from Unit myUnit where myUnit.memo = ?1"),
		@NamedQuery(name = "findUnitByMemoContaining", query = "select myUnit from Unit myUnit where myUnit.memo like ?1"),
		@NamedQuery(name = "findUnitByName", query = "select myUnit from Unit myUnit where myUnit.name = ?1"),
		@NamedQuery(name = "findUnitByNameContaining", query = "select myUnit from Unit myUnit where myUnit.name like ?1"),
		@NamedQuery(name = "findUnitByPrimaryKey", query = "select myUnit from Unit myUnit where myUnit.id = ?1") })

@Table(catalog = "pig", name = "unit")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "Unit")
@XmlRootElement(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain")
public class Unit implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "Name", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String name;
	/**
	 */

	@Column(name = "Memo")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String memo;

	/**
	 */
	@OneToMany(mappedBy = "unit", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.CureTaskMedicine> cureTaskMedicines;
	/**
	 */
	@OneToMany(mappedBy = "unit", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.FodderType> fodderTypes;
	/**
	 */
	@OneToMany(mappedBy = "unitByUnitId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.PreventionType> preventionTypesForUnitId;
	/**
	 */
	@OneToMany(mappedBy = "unitByUnitId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.PreventionType> preventionTypesForReportUnitId;
	/**
	 */
	@OneToMany(mappedBy = "unit", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.CureMedicine> cureMedicines;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 */
	public String getName() {
		return this.name;
	}

	/**
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 */
	public String getMemo() {
		return this.memo;
	}

	/**
	 */
	public void setCureTaskMedicines(Set<CureTaskMedicine> cureTaskMedicines) {
		this.cureTaskMedicines = cureTaskMedicines;
	}

	/**
	 */
	@JsonIgnore
	public Set<CureTaskMedicine> getCureTaskMedicines() {
		if (cureTaskMedicines == null) {
			cureTaskMedicines = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CureTaskMedicine>();
		}
		return cureTaskMedicines;
	}

	/**
	 */
	public void setFodderTypes(Set<FodderType> fodderTypes) {
		this.fodderTypes = fodderTypes;
	}

	/**
	 */
	@JsonIgnore
	public Set<FodderType> getFodderTypes() {
		if (fodderTypes == null) {
			fodderTypes = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.FodderType>();
		}
		return fodderTypes;
	}

	/**
	 */
	public void setPreventionTypesForUnitId(Set<PreventionType> preventionTypesForUnitId) {
		this.preventionTypesForUnitId = preventionTypesForUnitId;
	}

	/**
	 */
	@JsonIgnore
	public Set<PreventionType> getPreventionTypesForUnitId() {
		if (preventionTypesForUnitId == null) {
			preventionTypesForUnitId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PreventionType>();
		}
		return preventionTypesForUnitId;
	}

	/**
	 */
	public void setPreventionTypesForReportUnitId(Set<PreventionType> preventionTypesForReportUnitId) {
		this.preventionTypesForReportUnitId = preventionTypesForReportUnitId;
	}

	/**
	 */
	@JsonIgnore
	public Set<PreventionType> getPreventionTypesForReportUnitId() {
		if (preventionTypesForReportUnitId == null) {
			preventionTypesForReportUnitId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PreventionType>();
		}
		return preventionTypesForReportUnitId;
	}

	/**
	 */
	public void setCureMedicines(Set<CureMedicine> cureMedicines) {
		this.cureMedicines = cureMedicines;
	}

	/**
	 */
	@JsonIgnore
	public Set<CureMedicine> getCureMedicines() {
		if (cureMedicines == null) {
			cureMedicines = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CureMedicine>();
		}
		return cureMedicines;
	}

	/**
	 */
	public Unit() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Unit that) {
		setId(that.getId());
		setName(that.getName());
		setMemo(that.getMemo());
		setCureTaskMedicines(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CureTaskMedicine>(that.getCureTaskMedicines()));
		setFodderTypes(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.FodderType>(that.getFodderTypes()));
		setPreventionTypesForUnitId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PreventionType>(that.getPreventionTypesForUnitId()));
		setPreventionTypesForReportUnitId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PreventionType>(that.getPreventionTypesForReportUnitId()));
		setCureMedicines(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CureMedicine>(that.getCureMedicines()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("name=[").append(name).append("] ");
		buffer.append("memo=[").append(memo).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Unit))
			return false;
		Unit equalCheck = (Unit) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
